package com.hetao.xx.activity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.GridView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import com.hetao.xx.game.model.User;
import com.hetao.xx.Global;
import com.hetao.xx.R;
import com.hetao.xx.adapter.LoadPageAdapter;
import com.hetao.xx.orm.UserVo;
import com.hetao.xx.service.IntentManager;
import com.hetao.xx.service.UserManager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

import static com.hetao.xx.service.IntentManager.StartClose;


public class LoadActivity extends AppCompatActivity {

    @SuppressLint("NonConstantResourceId")
    @BindView(R.id.load_grid)
    GridView gridView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_load);
        ButterKnife.bind(this);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        toolbar.setTitle("输入昵称");


        List<UserVo> userList = UserManager.loadUserList();
        if (userList != null) {

            LoadPageAdapter adapter = new LoadPageAdapter(this, userList);
            gridView.setAdapter(adapter);

            gridView.setOnItemClickListener((parent, view, position, id) -> {

                UserVo userVo = userList.get(position);
                User user = UserManager.fullUserArms(userVo);
                Global.getInstant().setUser(user);

                IntentManager.toMain(this);
                setResult(StartClose);
                finish();
            });
        }
    }


}
